#include "adddiluent.h"


AddDiluent::AddDiluent(QWidget *parent) : QWidget(parent)
{
    optName = "addDiluent";
    virtualDevice = VirtualDevice::getInstance();
    processBarDialog = new ProcessBarDialog();
    countKeyTimer = new QTimer(this);
    timeFuncTimer = new QTimer(this);
    timeFuncTotalTime = 0;
    timeUnits = 0;
    processValue = 0;
    timeFuncState = VirtualDevice::Idle;
    connect(virtualDevice, SIGNAL(timeFuncCompelet(IVirtualDevice::TimeFunctionState)),this,SLOT(onTimeFuncCompelet(IVirtualDevice::TimeFunctionState)));
    connect(countKeyTimer,SIGNAL(timeout()),this, SLOT(on_countKeyTimer_Timeout()));
    connect(timeFuncTimer, SIGNAL(timeout()),this,SLOT(on_timeFuncTimer_Timeout()));
    countKeyTimer->setInterval(50);
    countKeyTimer->start();
}

AddDiluent::~AddDiluent()
{
}

void AddDiluent::showProcessDialog()
{
    processBarDialog->exec();
}

void AddDiluent::on_countKeyTimer_Timeout()
{
    if(timeFuncState == VirtualDevice::Running){
        //todo
    } else if(virtualDevice->getKeyState() == 1) {
        timeFuncState = VirtualDevice::Running;
        timeFuncTotalTime = virtualDevice->sendTimeFunc(optName,"F000");//F000 is for test
        timeFuncTotalTime *= 1000;
        timeUnits = timeFuncTotalTime/100;
        processValue = 0;
        timeFuncTimer->start(timeUnits);
    }
    countKeyTimer->start();
}

void AddDiluent::on_timeFuncTimer_Timeout(){
    if(++processValue > 96){
        processValue = 96;
        processBarDialog->setProcessBarValue(processValue);
    }
    timeFuncTimer->start(timeUnits);
}

void AddDiluent::onTimeFuncCompelet(IVirtualDevice::TimeFunctionState tfSta)
{

}



